package com.novax.ex.activity.provider.service;

import com.novax.ex.activity.infrastructure.entity.MallProductTitleLanguage;
import com.novax.ex.activity.infrastructure.mapper.MallProductTitleLanguageMapper;
import com.novax.ex.activity.open.model.response.MallPrizeResponse;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import com.novax.ex.common.enums.LanguageType;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.Objects;

/**
 * Description:展示名配置
 *
 * @author Deucalion@novax.email
 * @date 2023/2/21 17:21
 */
@Service
public class MallProductTitleLanguageService extends BaseService {
    @Resource
    private MallProductTitleLanguageMapper mallProductTitleLanguageMapper;
    @Override
    protected BaseMapper getBaseMapper() {
        return mallProductTitleLanguageMapper;
    }

    /** 根据语言查询数据 */
    public MallProductTitleLanguage findByLanguage(Long mallProductId, String language) {
        return mallProductTitleLanguageMapper.selectByLanguage(mallProductId,language);
    }

    /**
     * @description: 获取title
     * @author: Wade
     * @date: 2/22/23 4:46 PM
     * @param: [prize, language]
     * @return: void
     **/
    public String getTitleByLanguage(Long mallProductId, String language) {
        MallProductTitleLanguage titleLanguage = mallProductTitleLanguageMapper.selectByLanguage(mallProductId, language);
        if (Objects.isNull(titleLanguage)) {
            //在查一次英语
            titleLanguage = mallProductTitleLanguageMapper.selectByLanguage(mallProductId, LanguageType.en.getType());
            if (Objects.nonNull(titleLanguage)) {
                return titleLanguage.getContent();
            }
        } else {
            return titleLanguage.getContent();
        }
        return "";
    }
}
